package org.zhouhe.modules.hotproject.action;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.zhouhe.base.BaseAction;
import org.zhouhe.modules.hotproject.service.HotProjectService;
import org.zhouhe.page.PageUtil;
import org.zhouhe.vo.HotProject;
import org.zhouhe.vo.HotProjectRegion;
import org.zhouhe.vo.Industry;
import org.zhouhe.vo.Investment;
import org.zhouhe.vo.Region;

public class HotProjectAction extends BaseAction {

	private static final long serialVersionUID = 896164905733014622L;
	private PageUtil pageUtil = new PageUtil();
	private Industry projectIndustry = new Industry();
	private Investment projectInvestment = new Investment();
	private Region region = new Region();
	private HotProject hotProject = new HotProject();
	private List<HotProject> hotProjectList;
	private List<Integer> regionIdList = new ArrayList<Integer>();
	private List<HotProjectRegion> hotProjectRegionList = new ArrayList<HotProjectRegion>();
	@Autowired
	private HotProjectService hotProjectService;

	public String saveOrUpdate() {
		if (hotProject.getHotProjectId() != null) {
			hotProject = hotProjectService.getHotProjectDetail(hotProject);
			for (HotProjectRegion pr : hotProject.getHotProjectRegions()) {
				regionIdList.add(pr.getRegion().getRegionId());
			}
		}
		return "saveOrUpdate";
	}

	public String saveOrUpdateDo() {
		if (hotProject.getHotProjectId() == null) {
			hotProjectService.save(hotProject, regionIdList);
		} else {
			hotProjectService.update(hotProject, regionIdList);
		}
		return "saveOrUpdateDo";
	}

	public String delete() {
		hotProjectService.delete(hotProject);
		return "delete";
	}

	public String list() {
		pageUtil = hotProjectService.getHotProjectList(pageUtil, hotProject, region.getRegionId(), projectIndustry.getIndustryId(), projectInvestment.getInvestmentId());
		return "list";
	}

	public void setPageUtil(PageUtil pageUtil) {
		this.pageUtil = pageUtil;
	}

	public PageUtil getPageUtil() {
		return pageUtil;
	}

	public void setRegion(Region region) {
		this.region = region;
	}

	public Region getRegion() {
		return region;
	}

	public void setHotProject(HotProject hotProject) {
		this.hotProject = hotProject;
	}

	public HotProject getHotProject() {
		return hotProject;
	}

	public void setHotProjectList(List<HotProject> hotProjectList) {
		this.hotProjectList = hotProjectList;
	}

	public List<HotProject> getHotProjectList() {
		return hotProjectList;
	}

	public void setHotProjectRegionList(List<HotProjectRegion> hotProjectRegionList) {
		this.hotProjectRegionList = hotProjectRegionList;
	}

	public List<HotProjectRegion> getHotProjectRegionList() {
		return hotProjectRegionList;
	}

	public void setProjectIndustry(Industry projectIndustry) {
		this.projectIndustry = projectIndustry;
	}

	public Industry getProjectIndustry() {
		return projectIndustry;
	}

	public void setRegionIdList(List<Integer> regionIdList) {
		this.regionIdList = regionIdList;
	}

	public List<Integer> getRegionIdList() {
		return regionIdList;
	}

	public void setProjectInvestment(Investment projectInvestment) {
		this.projectInvestment = projectInvestment;
	}

	public Investment getProjectInvestment() {
		return projectInvestment;
	}
}
